'Option Explicit

Dim doc
Set doc = application.ActiveDocument
GetUserLicence(doc)
main
sub main()
	dim ostr:ostr = ""
	dim pcbnet,pcbnets
	set pcbnets = doc.nets(0)
	dim netname
	dim isAdd
	for each pcbnet in pcbnets
		netname = pcbnet.name
		isAdd = true
		if len(netname)>4 and left(netname,4)="XSIG" then isAdd = false
		if netname="(Net0)" or netname="GND" then isAdd = false
		if isAdd = true then
			if ostr<>"" then ostr = ostr & vbCrlf
			ostr = ostr & netname			
		end if
	next
	
	dim output:output = doc.path & "output\net.txt"
	dim fso,fw
	set fso = createobject("scripting.filesystemobject")
	set fw = fso.createTextfile(output,1)
	fw.write(ostr)
	fw.close
	set fw = nothing
	set fso =nothing
	
	dim wsh:set wsh = createobject("wscript.shell")
	'wsh.run(doc.path & "output")
	wsh.run output
	set wsh = nothing
end sub



' Function to validate document
Private Function ValidateServer(docObj)
    Dim key, licenseServer, licenseToken
    key = docObj.Validate(0)
    Set licenseServer = CreateObject("MGCPCBAutomationLicensing.Application")
    licenseToken = licenseServer.GetToken(key)
    Set licenseServer = nothing
    'On Error Resume Next
    Err.Clear
    docObj.Validate(licenseToken)
    If Err Then
        ValidateServer = 0    
    Else 
        ValidateServer = 1
    End If
End Function

sub GetUserLicence(docObj)

	If ValidateServer(docObj) = 0 Then
	    msgbox "Server validation failed."
	    exit sub
	End If
	
end sub
'---------------------------------------------------------------------




